﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SOMClustering
{
    public delegate void OnNewProjectAccepted(NewProjectAcceptedEventArgs e);

    public partial class ProjectCreateWindow : Form
    {
        public OnNewProjectAccepted newProjectAccepted;
        public String NameBase = "ПроектКластеризации";

        public ProjectCreateWindow()
        {
            InitializeComponent();
        }

        private void ProjectCreateWindow_Load(object sender, EventArgs e)
        {
            textBoxFolder.Text = Environment.GetFolderPath(
                Environment.SpecialFolder.MyDocuments)  + "\\SOM\\";
            SetFileName();
        }

        private void SetFileName()
        {
            int i = 1;
            while (System.IO.Directory.Exists(textBoxFolder.Text + NameBase + i.ToString()))
                i++;
            textBoxProjectName.Text = NameBase + i.ToString();
        }

        private void buttonSelectFolder_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbFolder = new FolderBrowserDialog();
            fbFolder.Description = "Выберите папку для сохранения проекта";
            fbFolder.RootFolder = Environment.SpecialFolder.MyDocuments;
            fbFolder.SelectedPath = textBoxFolder.Text;
            if (fbFolder.ShowDialog() == DialogResult.OK)
            {
                textBoxFolder.Text = fbFolder.SelectedPath;
                SetFileName();
            }
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (newProjectAccepted != null)
            {
                NewProjectAcceptedEventArgs projectData = new NewProjectAcceptedEventArgs();
                projectData.ProjectFolderName = textBoxFolder.Text;
                projectData.ProjectName = textBoxProjectName.Text;
                newProjectAccepted.Invoke(projectData);
            }
        }
    }
}